<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
	<script type="text/javascript" src="__PUBLIC__/js/easyuiValidatebox.js"></script>
	<style type="text/css">
		div,span{
			font-size: 14px;
			color: #444444;
		}
		tr td{
			font-size: 12px;
			color: #444444;
		}
		th{
			font-size: 12px;
			color: #444444;
		}
	</style>
	<script type="text/javascript">
	$(function(){
		//判断是否闰年
		function isLeapYear(year){
	        if(year % 4 == 0 && ((year % 100 != 0) || (year % 400 == 0)))
	        {
	             return true;
	        }
	        return false;
	    }

        //判断前后两个日期
        function validatePeriod(fyear,fmonth,fday,byear,bmonth,bday){
            if(fyear < byear){
            	return true;
            }else if(fyear == byear){
	            if(fmonth < bmonth){
	               return true;
	            } else if (fmonth == bmonth){
	               if(fday <= bday){
	                return true;
	               }else {
	                return false;
	               }
	            } else {
	               return false;
	            }
            }else {
            	return false;
            }
        }

        //计算两个日期的差值
        function dateDiff(d1,d2){
	        var disNum=compareDate(d1,d2);
	        return disNum;
	    }

	    //计算
	    function compareDate(date1,date2){
            var regexp=/^(\d{1,4})[-|\.]{1}(\d{1,2})[-|\.]{1}(\d{1,2})$/;
            var monthDays=[0,3,0,1,0,1,0,0,1,0,0,1];
            regexp.test(date1);
            var date1Year=RegExp.$1;
            var date1Month=RegExp.$2;
            var date1Day=RegExp.$3;

            regexp.test(date2);
            var date2Year=RegExp.$1;
            var date2Month=RegExp.$2;
            var date2Day=RegExp.$3;

	        if(validatePeriod(date1Year,date1Month,date1Day,date2Year,date2Month,date2Day)){
	        firstDate=new Date(date1Year,date1Month,date1Day);
	             secondDate=new Date(date2Year,date2Month,date2Day);

	             result=Math.floor((secondDate.getTime()-firstDate.getTime())/(1000*3600*24));
	             for(j=date1Year;j<=date2Year;j++){
	                 if(isLeapYear(j)){
	                     monthDays[1]=2;
	                 }else{
	                     monthDays[1]=3;
	                 }
	                 for(i=date1Month-1;i<date2Month;i++){
	                     result=result-monthDays[i];
	                 }
	             }
	             return result;
	        }else{
	        	$.messager.alert('错误', '对不起，开始时间必须小于结束时间，谢谢！', 'info');
	            exit;
	        }
	    }

		//实例化datetimebox开始时间
		$('#startTime').datetimebox({
            showSeconds: false,
            required: true,
            onChange: function(date){

            	var startTime=$("#startTime").datetimebox('getValue');
            	st = new Array;
 				st = startTime.split(" ");
 				startTime=st[0];
            	var endTime=$("#endTime").datetimebox('getValue');
				et = new Array;
 				et = endTime.split(" ");
 				endTime=et[0];
 				if(endTime!="" && startTime!=""){
 					var dates=dateDiff(startTime,endTime);
 					$('#dayNumber').val(dates);
 				}
				
			}
        });

					
        //实例化datetimebox结束时间
		$('#endTime').datetimebox({
            showSeconds: false,
            required: true,
            onChange: function(date){

            	var startTime=$("#startTime").datetimebox('getValue');
            	st = new Array;
 				st = startTime.split(" ");
 				startTime=st[0];
            	var endTime=$("#endTime").datetimebox('getValue');
				et = new Array;
 				et = endTime.split(" ");
 				endTime=et[0];

 				if(startTime==""){
 					$.messager.alert('提醒', '请输入开始时间，谢谢！', 'info');
 				}
 				if(startTime!="" && endTime!=""){
 					var dates=dateDiff(startTime,endTime);
 					$('#dayNumber').val(dates);
 				}
 				
				
				
			}
        });


		

		$('#addleavefrm').form({
			url:'__URL__/addLeavePost',
		    onSubmit:function(){
		        return $(this).form('validate');
		    },
		    success:function(data){
		        $.messager.alert('Info', data, 'info');
		    }

		});

		$('.save').click(function(){
			$.ajax({
				type:'POST',
				url:'__URL__/savePost',
				data:$('form').serialize(),
				success:function(data){
					$.messager.alert('Info', data, 'info');
				}
			})

		})

	})

	</script>
</head>
<body>


<form id="addleavefrm" method="post">
<div id="printDiv" style="text-align: center; margin: 0 auto;">
	<div>
		<span id="processInsId" style="float: right;"></span>
		<span id="formTitle" class="title">请假申请单</span>
	</div>
	<div id="formDiv">
		<table class="editTable" style="width:100%; border-collapse: collapse; line-height:22px; margin-top:3px;">
			<colgroup span="6" width="16%"></colgroup>
		<tbody>
			<volist name="approvalData" id="vo">
			<tr>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">申请人：</td>
				<td style="text-align: left; width:80%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<volist name="nowEmployeData" id="voo">
						<input id="employe_name" name="employe_name" type="text" value="{$voo.employe_name}" readonly="readonly" /></td>
					</volist>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">流程号：</td>
				<td style="text-align: left; width:80%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<volist name="processData" id="voo">
						<input class="leave_process_id" name="leave_process_id" readonly="readonly" value="{$voo.process_num}" />
						<input name="process_id" type="hidden" value="{$voo.process_id}"/>
					</volist>
				</td>
			</tr>
			<tr>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">职位：</td>
				<td style="text-align: left; width:80%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<input id="position" name="leave_position" type="text" value="{$position_name}" readonly="readonly" />
					<input name="leave_position_id" type="hidden" value="{$employe_position_id}" />
				</td>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">部门：</td>
				<td style="text-align: left; width:80%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<input id="dpt_name" name="dpt_name" type="text" value="{$dpt_name}" readonly="readonly" />
					<input name="leave_department_id" type="hidden" value="{$employe_department_id}" />
				</td>
			</tr>


			
			<tr>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">开始时间：</td>
				<td style="text-align: left; width:32%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<input id="startTime" class="easyui-datetimebox" name="leave_begin_time" value="{$vo.leave_begin_time}"/>&nbsp;*</td>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">结束时间：</td>
				<td style="text-align: left; width:32%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<input id="endTime" name="leave_end_time" type="text" value="{$vo.leave_end_time}" />&nbsp;*</td>
			</tr>
			<tr>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">请假天数：</td>
				<td style="text-align: left; width:32%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<input id="dayNumber" name="leave_date_num"  type="text" readonly="readonly" value="{$vo.leave_date_num}" />&nbsp;*</td>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">请假类型：</td>
				<td style="text-align: left; width:32%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="2">
					<select id="vacationtypeId" name="leave_type">
						<option value="事假" <eq name="vo.leave_type" value="事假">selected="selected"</eq>>事假</option>
						<option value="病假" <eq name="vo.leave_type" value="病假">selected="selected"</eq>>病假</option>
						<option value="调休" <eq name="vo.leave_type" value="调休">selected="selected"</eq>>调休</option>
						<option value="婚假" <eq name="vo.leave_type" value="婚假">selected="selected"</eq>>婚假</option>
						<option value="产假" <eq name="vo.leave_type" value="产假">selected="selected"</eq>>产假</option>
						<option value="年假" <eq name="vo.leave_type" value="年假">selected="selected"</eq>>年假</option>
						<option value="护理假" <eq name="vo.leave_type" value="护理假">selected="selected"</eq>>护理假</option>
						<option value="丧假" <eq name="vo.leave_type" value="丧假">selected="selected"</eq>>丧假</option>
						<option value="其他" <eq name="vo.leave_type" value="其他">selected="selected"</eq>>其他</option>
					</select>
					&nbsp;*
				</td>
				
			</tr>
			<tr>
				<td style="padding: 3px; border: 1px solid #D3D3D3; text-align: left; width:96%;" colspan="6">
					<div id="attendPrompt"></div>
				</td>
			</tr>
			<tr>
				<td style="width:16%; text-align: right; background-color: #f1f9fe; padding: 3px; border: 1px solid #D3D3D3; ">请假事由：</td>
				<td style="text-align: left; width:80%;  padding: 3px; border: 1px solid #D3D3D3; " colspan="5">
					<textarea id="content" name="leave_reason" style="width:90%;height:40px;">{$vo.leave_reason}</textarea>
					&nbsp;*
				</td>
			</tr>
			</volist>

			
		</tbody>
	</table>
</div>
</div>

<div id="operSet" style="display:none; padding-top:10px;" class="noprint">
<div class="formTitle">任务执行人设置</div>
<table class="listTable3">
	<thead>
		<tr>
			<th>任务名称</th>
			<th>执行人</th>
		</tr>
	</thead>
	<tbody id="listTbody"></tbody>
</table>
</div>

<div id="nextStepSet" style="padding-top: 10px;" class="noprint">
<div class="title">下一步任务设置</div>
<div id="nextStepCont">
	<table class="editTable" style="width:100%;border: 1px solid #D3D3D3">
		<tbody>
			<tr style="border: 1px solid #D3D3D3;">
				<th style="border: 1px solid #D3D3D3;">任务执行人：</th>
				<td style=" border: 1px solid #D3D3D3;">
					<span id="noper_420">
						<input id="oper_420" value="" type="hidden">
						<input readonly="readonly" id="check_person" class="easyui-validatebox" name="check_person" onclick="doSearch()" type="text" data-options="required:true" value="{$process_now_name}"/>
						<input type="hidden" id="check_person_id" name="check_person_id"/>
						<span style="margin-left: 15px;">
							<input id="im_420" checked="checked" type="checkbox">消息提醒</span>
						<span style="margin-left: 15px;">
							<input id="sms_420" type="checkbox">手机提醒</span>
					</span>
				</td>
			</tr>
		</tbody>
	</table>
</div>
</div>

<input type="submit" value="提交" />
<input class="save" type="button" value="保存" />
</form>

<include file="Common:checkPerson"/>
</body>
</html>